<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet"
	href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css"
	integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
	crossorigin="anonymous">
<link type="text/css" rel="stylesheet" href="/static/css/main.css" />
<script type="text/javascript"
	src="https://cdn.bootcss.com/jquery/1.12.1/jquery.min.js"></script>
<script type="text/javascript">
	$(function() {
		$("#setButton")
				.click(
						function() {
							var whenIfVal = $("input[name='whenIf']:checked")
									.val();
							var thenDoVal = getCheckBoxVal("thenDo");
							$("#flowInnerDiv").empty();
							if (whenIfVal == "buySumMoney") {
								$("#flowInnerDiv").append(
										"<p>当满足下列条件:</p> </br>");
								$("#flowInnerDiv")
										.append(
												"<input type='text' name='minValue' placeholder='请输入一个合理数值'/><h>&lt;订单购买金额&lt;</h> <input type='text' name='maxValue' placeholder='请输入一个合理数值'/> </br>");
							} else if (whenIfVal == "latestOrderTime") {
								$("#flowInnerDiv")
										.append(
												"<input type='text' name='minValue' placeholder='请输入一个合理数值'/><h>&lt;距离当前时间多少天&lt;</h> <input type='text' name='maxValue' placeholder='请输入一个合理数值'/> </br>");
							} else if (whenIfVal == "buyNum") {
								$("#flowInnerDiv")
										.append(
												"<input type='text' name='minValue' placeholder='请输入一个合理数值'/><h>&lt;购买次数&lt;</h> <input type='text' name='maxValue' placeholder='请输入一个合理数值'/> </br>");
							} else {
								alert("请先选择!!!")
								return;
							}
							$("#flowInnerDiv").append("</br><p>进行如下操作:</p> </br>");
							if ($.inArray("level", thenDoVal) != -1) {
								$("#flowInnerDiv")
										.append(
												"<p>设置会员等级为:<input type='text' name='levelValue' value='' placeholder='请输入一个等级值' /></p></br>");
							}
							if ($.inArray("buyLevel", thenDoVal) != -1) {
								$("#flowInnerDiv")
										.append(
												"<p>设置会员复购等级为:<input type='text' name='buyLevelValue' value='' placeholder='请输入一个复购等级值' /></p></br>");
							}
							if ($.inArray("points", thenDoVal) != -1) {
								$("#flowInnerDiv")
										.append(
												"<p>设置会员积分为:<input type='text' name='pointsValue' style='width:550px;' placeholder='请输入一个计算表达式，buySumMoney 代表订单总额 例：   60+BuySumMoney*1.2' /></p></br>");
							}
							$("#flowDiv").show();
						});
		//生成规则按钮
		$("#createRule").click(function() {
			$("#ruleForm").submit();
		});
	});
	//获取checkBox选择值
	function getCheckBoxVal(name) {
		var checkArr = new Array();
		$("[name = " + name + "]:checkbox").each(function() {
			if ($(this).is(":checked")) {
				checkArr.push($(this).attr("value"));
			}
		});
		return checkArr;
	}
</script>
</head>
<body>
	<form id="ruleForm" th:action="@{/rules/createRule}"  method="post">
		<h>请选择判断条件:</h>
		</br> <input type="radio" name="whenIf" value="buySumMoney" />总订单金额 <input
			type="radio" name="whenIf" value="latestOrderTime" />最近下单时间 <input
			type="radio" name="whenIf" value="buyNum" />购买次数 </br>
		<h>请选择执行条件:</h>
		</br> <input type="checkbox" name="thenDo" value="level" />会员等级 <input
			type="checkbox" name="thenDo" value="buyLevel" />会员复购等级 <input
			type="checkbox" name="thenDo" value="points" />会员积分 </br> <input
			type="button" id="setButton" value="设置" />

		<div id="flowDiv" style="display: none;">
			<div id="flowInnerDiv"> </div>
			</br><span> 规则名称: <input type="text" name="ruleName" placeholder="请输入一个规则名称" /> <span> </br> 
			<span>规则执行顺序:<input
				type="text" value="1" name="ruleOrder"
				placeholder="请输入一个规则执行顺序，越大执行优先级越高" /></span>
			</br> 
			<span>规则组:<input
				type="text" value="" name="ruleGroup"
				placeholder="可为空,规则组内只有一个规则能够执行" /></span>
			</br> 
			<input type="button"
				value="生成规则" id="createRule" />
		</div>
	</form>


</body>
</html>